<?php 


	//cookie 	 记录在客户端上
	//setcookie()  写COOKIE数据


	//session 	 会话  建立链接后产生一个会话session_id  
	//存在会话时长	会话超时，由服务器产生id  在服务器内存里 临时存在
	//session_start  启动一个会话  写在最前面  $_SESSION['']


	//http https 无状态的传输协议
	//header("Content-Type:text/html;charset=UTF-8");
	class DB{
		private $db;
		function __construct()
		{
			$this->db = new mysqli("localhost",'root','root','xlj') or die("链接失败".$this->db->connect_error);	
		}
		function createTable($sql)
			{
				$this->db->query($sql);
				if ($this->db->error) {
					echo "失败".$this->db->error;
					return false;
				}else{
					echo "创建表成功！";
					return true;
				}
			}
			function insert($sql)
			{
				$this->db->query($sql);
				if ($this->db->error) {
					echo "插入失败".$this->db->error;
					return false;
				}else{
					//echo "成功插入".$this->db->affected_rows."条数据";
					return true;
				}
			}
			function get($sql)
		{
			$res = $this->db->query($sql);
			if ($this->db->errno) {
				echo "没有获取到数据".$this->db->error;
				return false;
			} else {
				return $res->fetch_all();
			}
		}
			function update($sql)
			{
				
				$this->db->query($sql);
				if ($this->db->error) {
					echo "更新失败".$this->db->error;
					return false;
				}else{
					echo "成功更新".$this->db->affected_rows."条数据";
					return true;
				}
			}
			function delete($sql)
			{
				$this->db->query($sql);
				if ($this->db->error) {
					echo "删除失败".$this->db->error;
					return false;
				}else{
					echo "成功删除".$this->db->affected_rows."条数据";
					return true;
				}
			}
			function getCount($sql)
			{
				$res = $this->db->query($sql);
				$count = $this->db->affected_rows;
				return $count;
			}
			function __destruct()
			{
				$this->db->close();
			}
	}
	

 ?>